package _16define.exercise;

public class Demo3 {
    public static void main(String[] args) throws CloneNotSupportedException {
        Star star=new Star(25,"邓紫棋");
        Student student=new Student(18,"汤晨宇",star);
        Teacher teacher=new Teacher(30,"景天",student);
        Teacher clone= teacher.clone();
        System.out.println(teacher==clone);
        System.out.println(teacher);
        System.out.println(clone);
        System.out.println(teacher.stu.s== clone.stu.s);
    }
}
class Teacher implements Cloneable{
    int age;
    String name;
    Student stu;

    public Teacher(int age, String name, Student stu) {
        this.age = age;
        this.name = name;
        this.stu = stu;
    }

    @Override
    public Teacher clone() throws CloneNotSupportedException {
        Teacher teacher=(Teacher)super.clone();
        Student student=teacher.stu.clone();
        teacher.stu=student;
        return teacher;
    }
}
class Student implements Cloneable{
    int age;
    String name;
    Star s;

    public Student(int age, String name, Star s) {
        this.age = age;
        this.name = name;
        this.s = s;
    }


    @Override
    public Student clone() throws CloneNotSupportedException {
        Student student=(Student)super.clone();
        Star star=student.s.clone();
        student.s=star;
        return student;
    }
}
class Star implements Cloneable{
    int age;
    String name;

    public Star(int age, String name) {
        this.age = age;
        this.name = name;
    }

    @Override
    public Star clone() throws CloneNotSupportedException {
        Object clone=super.clone();
        Star star=(Star) clone;
        return star;
    }
}